﻿using AccessibilityTools.DB;
using AccessibilityTools.DB.Serivce;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TianYi.Bll
{
   public class ProductionDetalisLogic
    {
        ProductionDetailsInfoDal productionDetailsInfoDal = new ProductionDetailsInfoDal();

        public List<ProductionDetailsInfo> AllList()
        {
            return productionDetailsInfoDal.Query();
        }

        public int Add(ProductionDetailsInfo log)
        {
           int count= productionDetailsInfoDal.Add(log);
            if (count>0)
            {
                return count;
            }
            return 0;
        }

        public List<ProductionDetailsInfo> SelectDetailsByDatetime(DateTime dtStart, DateTime dtEnd)
        {
            return productionDetailsInfoDal.QueryYieldInfoByDate(dtStart, dtEnd);
        }
        public ProductionDetailsInfo GetInstance(string sn)
        {
            return productionDetailsInfoDal.QuerySingle(sn);
        }

        public List<ProductionDetailsInfo> SelectDetailsByQrCode(string qrCode)
        {
            return productionDetailsInfoDal.QueryByQrCode(qrCode);
        }

        public List<ProductionDetailsInfo> SelectDetailsByDatetimeAndType(DateTime dtStart, DateTime dtEnd, string productType)
        {
            return productionDetailsInfoDal.QueryByDatetimeAndType(dtStart, dtEnd, productType);
        }

        public bool Delete(int sn)
        {
            bool p = productionDetailsInfoDal.Delete(sn);
            return p;
        }

        public int Update(ProductionDetailsInfo Instance)
        {
            int result = productionDetailsInfoDal.Update(Instance);
            if (result > 0)
            {
                return 1;
            }
            return 0;
        }

        public ProductionDetailsInfo GetListByTime()
        {
            ProductionDetailsInfo Instance= productionDetailsInfoDal.GetListByTime();
            return Instance;
        }
        public List<string> GetDistinctProductTypes()
        {
            return productionDetailsInfoDal.Queryable()
                                           .Select(x => x.ProductTypes)
                                           .Distinct()
                                           .ToList();
        }
    }
}
